package com.dcbeida.activity.stockdetail;


import android.app.Activity;
import android.content.DialogInterface;
import android.support.annotation.Nullable;

import com.dcbeida.MyApplication;
import com.dcbeida.activity.sales.StoresalesContract;
import com.dcbeida.activity.sales.StoresalesPresenter;
import com.dcbeida.bean.Drug;
import com.dcbeida.bean.DrugInfo;
import com.dcbeida.bean.DrugListBean;
import com.dcbeida.bean.PatientList;
import com.dcbeida.bean.Result_Api;
import com.dcbeida.callback.DialogCallback;
import com.dcbeida.model.InventoryModel;
import com.dcbeida.model.SotresalesModel;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

import okhttp3.Call;
import okhttp3.Response;

/**
 * Created by hp on 2016/5/12.
 */
public class RkStockDetailEditPresenter implements RkStockDetailEditContract.Present {


    private RkStockDetailEditContract.View view;

    private List<DrugInfo> drugInfoList;

    private InventoryModel model2;

    private SotresalesModel model;


    private Activity act;

    public RkStockDetailEditPresenter(RkStockDetailEditContract.View view, Activity act) {
        //我这里直接把activity作为view，所以不需要
        //mView.setPresenter(this);
        this.view = view;
        drugInfoList = new ArrayList<>();
        model2 = InventoryModel.newInstance();
        model = SotresalesModel.newInstance();
        this.act = act;

    }







    @Override
    public void start() {

    }

    //取消dialog 取消请求
    DialogInterface.OnCancelListener lis = new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            model2.getCancel();
        }
    };

    @Override
    public void modifyDetail(String stockinlogid, String provideName, String provideId, String money) {
        model2.updatestockinlog(stockinlogid,provideName,provideId,money,new ApiCallBack(act, Result_Api.class, lis));
    }


    //药店销售-新增销售记录 返回结果
    class ApiCallBack<T> extends DialogCallback<T> {

        public ApiCallBack(Activity activity, Class<T> tclass, DialogInterface.OnCancelListener listener) {
            super(activity, tclass, listener);
        }

        @Override
        public void onResponse(T data) {
            if (data != null) {
                if (((Result_Api) data).getCode() == 1) {
                    view.showTelTip(((Result_Api) data).getMsg());
                    view.confimSuccess();
                }
            }
        }


        public void onError(boolean isFromCache, Call call, @Nullable Response response, @Nullable Exception e) {
            super.onError(call, response, e);
            //view.showTip("数据未请求成功,请检查网络...");

        }
    }

}
